// 小红的ABC(找规律)
#include <iostream>
#include <string>
using namespace std;

string s;
int len = -1;

int main()
{
    cin >> s;
    int n = s.size();
    for (int i = 1; i < n; i++)
    {
        if (s[i] == s[i - 1]) 
        {
            len = 2;
            break;
        }
        if (i + 1 < n && s[i - 1] == s[i + 1]) len = 3;
    }
    cout << len << endl;
    return 0;
}

// 不相邻取数(多状态dp)
#include <iostream>
using namespace std;

const int N = 2e5 + 1;
int n;
int arr[N], f[N], g[N];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    for (int i = 1; i <= n; i++)
    {
        f[i] = g[i - 1] + arr[i];
        g[i] = max(g[i - 1], f[i - 1]);
    }
    cout << max(f[n], g[n]) << endl;
    return 0;
}

// 空调遥控(排序+二分/滑动窗口)
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1e6 + 1;
int arr[N];
int n, p, res;

int func(int k)
{
    int a = k - p, b = p + k;
    int begin = 0, l = 0, r = n - 1;
    while (l < r)
    {
        int mid = l + (r - l) / 2;
        if (arr[mid] < a) l = mid + 1;
        else r = mid;
    }
    begin = l;
    l = 0, r = n - 1;
    while (l < r)
    {
        int mid = l + (r - l + 1) / 2;
        if (arr[mid] <= b) l = mid;
        else r = mid - 1;
    }
    return r - begin + 1;
}

int main()
{
    cin >> n >> p;
    for (int i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr + n);
    for (int i = 0; i < n; i++)
    {
        res = max(res, func(arr[i]));
    }
    cout << res << endl;
    return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1e6 + 1;
int n, p, res;
int arr[N];

int main()
{
    cin >> n >> p;
    for (int i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr + n);
    p *= 2;
    for (int l = 0, r = 0; r < n; r++)
    {
        while (arr[r] - arr[l] > p) l++;
        res = max(res, r - l + 1);
    }
    cout << res << endl;
    return 0;
}
